package bradd.tom;

import java.sql.Date;





import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Report extends Activity  {
	
	Databasehelper dbasehelper;
	TextView[] expire;
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.report);
	        
	        Button button = (Button)findViewById(R.id.goback);
	        button.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent goback = new Intent(Report.this, Tom.class);
					Report.this.startActivity(goback);	
					
				}
			});
	        dbasehelper = new Databasehelper(this, 2);
	        findreport();
	 }
public void findreport()
{
	String q = "select Product_name, Exp_Date from inventory where date(Exp_Date) < date('now','+7 days');";
	SQLiteDatabase read = dbasehelper.getReadableDatabase();
	
	Cursor cur = read.rawQuery(q, null);
	startManagingCursor(cur);
	 cur.moveToFirst();
     

	
	expire= new TextView[5];
    expire[0] = (TextView)findViewById(R.id.expire1);
    expire[1] = (TextView)findViewById(R.id.expire2);
    expire[2] = (TextView)findViewById(R.id.expire3);
    expire[3] = (TextView)findViewById(R.id.expire4);
    expire[4] = (TextView)findViewById(R.id.expire5);
    
    while (cur.isAfterLast() == false) {
    	for (int i = 0; i < 5; i++)
        {expire[i].setText(cur.getString(0) + "expire on" + " " + cur.getString(1));
   	    cur.moveToNext();}
    }
    cur.close();
}

	
}
